package com.lzw.okgoutils.http.struct;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class StringFileMap extends HashMap<String, FileBody> {

    public List<String> getKeyList(){
        List<String> keyList = new ArrayList<String>();
        for (Entry<String, FileBody> entry : entrySet()) {
            keyList.add(entry.getKey());
        }
        return keyList;
    }


    public List<FileBody> getFileBodyList(){
        List<FileBody> list = new ArrayList<FileBody>();
        for (Entry<String, FileBody> entry : entrySet()) {
            list.add(entry.getValue());
        }
        return list;
    }

    public List<File> getRawFileList(){
        List<File> list = new ArrayList<File>();
        for (Entry<String, FileBody> entry : entrySet()) {
            list.add(entry.getValue().getFile());
        }
        return list;
    }

    @Override
    public String toString() {
        if (isEmpty()) {
            return "[]";
        }
        StringBuilder sb = new StringBuilder();
        for (Entry<String, FileBody> entry : this.entrySet()) {
            sb.append("[")
                    .append(entry.getKey())
                    .append("=")
                    .append(entry.getValue().getFile().getPath())
                    .append("]")
                    .append(",");
        }
        String res = sb.toString();
        return res.substring(0, res.length()-1);
    }
}
